-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor away state in Nav menu selector #45464
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
|
||
if ( isCreatingMenu || isResolvingNavigationMenus ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this loading state conditional on actually being in a resolving state rather than whether we have resolved or not.
|
||
let enableOptions = false; | ||
|
||
if ( isCreatingMenu ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition was dotted about. I've centralise it here. If we are creating then never show the options.
packages/block-library/src/navigation/edit/navigation-menu-selector.js
Outdated
Show resolved
Hide resolved
packages/block-library/src/navigation/edit/navigation-menu-selector.js
Outdated
Show resolved
Hide resolved
Size Change: +586 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
82f9963
to
dea3e92
Compare
I refactored this using the unit tests to check the behaviour remains the same
We should verify the behaviour is correct with manual testing just to ensure the tests cover all the scenarios. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
}, [ | ||
isCreatingMenu, | ||
createNavigationMenuIsError, | ||
createNavigationMenuIsSuccess, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add setIsCreatingMenu
as a dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useState
setters are guaranteed by React to display referential equality. I think this is because they derive from dispatch
which is the same. I can double check that but I'm pretty sure it's correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to pass it as a dependency because we think it might change, only because we have a warning about undeclared dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I committed a change. Does that work?
packages/block-library/src/navigation/edit/navigation-menu-selector.js
Outdated
Show resolved
Hide resolved
Flaky tests detected in 90b6737. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4312930770
|
What?
Aims to refactor away the use of setState in favour of computed values in order to simplify the logic and improve the handling in the Navigation block's menu selector within the inspector controls.
Why?
The current code is
How?
This PR aims to:
Testing Instructions
Screenshots or screencast